# Usage:
# make #compile all binary
# make clean #remove ALL binaries and objects
#
#PHONY = all clean
CC = gcc
SUBDIRS = $(shell ls -l |grep ^d | awk '{if($$9 != "debug") print $$9}')
ROOT_DIR = $(CURDIR)
OBJS_DIR = $(ROOT_DIR)/debug/obj
BIN_DIR = $(ROOT_DIR)/debug/bin
BIN = $(BIN_DIR)/my_app

CUR_SOURCE= $(wildcard *.c)
CUR_OBJS = ${patsubst %.c, $(OBJS_DIR)/%.o, $(CUR_SOURCE)}

export CC BIN OBJS_DIR BIN_DIR ROOT_DIR
all: $(SUBDIRS) $(CUR_OBJS) DEBUG

$(SUBDIRS): FORCE
	@make --no-print-directory -C $@

DEBUG:
	@make --no-print-directory -C debug

$(CUR_OBJS):$(OBJS_DIR)/%.o:%.c
	@echo "CC $(notdir $@)"
	@$(CC) -c $^ -o $@

clean:
	@rm $(OBJS_DIR)/*.o

FORCE:


.PHONY: clean $(SUBDIRS) DEBUG FORCE
